package cn.stockinservice.mapper;

import cn.stockinservice.po.StockIn;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

public interface StockInMapper {
    @Select("select s.id,s.order_no as orderNo,s.product_code as productCode," +
            "s.quantity,s.remark,s.create_time as createTime from stock_in s where id = #{stockInId}")
    StockIn findByStockInId(@PathVariable Long stockInId);

    @Select("select s.id,s.order_no as orderNo,s.product_code as productCode," +
            "s.quantity,s.remark,s.create_time as createTime from stock_in s")
    List<StockIn> queryAllStockIn();

    @Delete("delete from stock_in where stock_in.id=#{stockInId}")
    boolean deleteStockIn(@PathVariable Long stockInId);

    @Insert("insert into stock_in (order_no,product_code,quantity,remark,create_time)" +
            "values (#{orderNo},#{productCode},#{quantity},#{remark},#{createTime})")
    boolean addNewStockIn(@RequestBody StockIn stockIn);

    @Update("update product set stock=stock+#{quantity} where id =#{productCode}")
    void updateProduct(@RequestBody StockIn stockIn);

    @Update("update stock_in set order_no=#{orderNo},product_code=#{productCode}," +
            "quantity=#{quantity},remark=#{remark},create_time=#{createTime} where id=#{id}")
    boolean updateStockIn(@RequestBody StockIn stockIn);
}
